// ==============================================================================================
// RibbonTabTreeNode.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.Entities;
using RibbonExplorer.InfoPanel;

namespace RibbonExplorer.Tree
{
  // ==============================================================================================
  /// <summary>
  /// This tree node represents a standard tab node in the tree.
  /// </summary>
  // ==============================================================================================
  public class RibbonTabTreeNode : OnDemandTreeNode, IInfoPanelSupport
  {
    #region Private Fields

    private RibbonTab _RibbonTab;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates the tree node instance.
    /// </summary>
    /// <param name="ribbonTab">Ribbon tab for this standard tab.</param>
    // --------------------------------------------------------------------------------------------
    public RibbonTabTreeNode(RibbonTab ribbonTab)
      : base(ribbonTab.Id)
    {
      _RibbonTab = ribbonTab;
      ImageKey = "RibbonTab";
      SelectedImageKey = ImageKey;
      Tag = _RibbonTab;
    }

    #endregion

    #region Public methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the tab representing this node.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public RibbonTab RibbonTab
    {
      get { return _RibbonTab; }
    }

    #endregion

    #region Overridden methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Handle the event when the tree node is fisrt time expanded.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected override void OnExpandFirstTime()
    {
      base.OnExpandFirstTime();
      _RibbonTab.LoadChildren();
      // --- Init groups belonging to this ribbon tab
      foreach (Group group in _RibbonTab.Groups)
      {
        Nodes.Add(new GroupTreeNode(group));
      }
    }

    #endregion

    #region IInfoPanelSupport implementation

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an infopanel instance for this tree node type.
    /// </summary>
    /// <param name="node">Tree node instance</param>
    /// <param name="navigationService">Navigation service instance</param>
    /// <returns>
    /// User control instance
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public virtual UserControl GetInfoPanelInstance(TreeNode node, INavigationSupport navigationService)
    {
      GenericInfoPanel control = new GenericInfoPanel(navigationService, node);
      control.HeaderText = "Tab: " + node.Text;
      return control;
    }

    #endregion
  }
}
